<template>
  <section>
    <el-select clearable v-model="selTactics" :filterable="true" remote
               :reserve-keyword="false" default-first-option  placeholder="请输入关键词"
               :remote-method="getList" size="mini">
      <el-option v-for="tactics in list" :key="tactics.id" :label="tactics.name" :value="tactics.id"/>
    </el-select>
    <el-tree>

    </el-tree>
  </section>
</template>

<script>
  import errHandler from '@/assets/errHandler.js'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  export default {
    name: "selTactics",
    props:['keyObj'],
    data(){
      return{
        list:null,
        selTactics:null,
        tacticsIndexList:null
      }
    },
    watch: {
      selTactics(nv, ov) {
        if (nv){
          this.$emit('selTactics',nv)
          this.getIndex(nv)
        }
      },
    },
    created(){
    },
    methods:{
      ...mapActions({
        fetch: 'fetch'
      }),
      getList(e){
        this.fetch({name:"getTacticsList",data:{...this.keyObj,key:e}})
          .then(res=>{
            console.log('策略列表-------',res)
            this.list=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      getIndex(tacticsId){
        this.fetch({name:"getTacticsIndexList",data:{tacticsId}})
          .then(res=>{
            console.log('获取该策略下的指标-------',res)
            this.tacticsIndexList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
    }
  }
</script>

<style scoped>

</style>
